import {
	Session
} from '@/utils/storage.js';

const userInfosModule = {
	namespaced: true,
	state: {
		userInfos: {},
		setting: Session.get('setting') || {}
	},
	mutations: {
		// 设置用户信息
		getUserInfos(state, data) {
			state.userInfos = data;
		},

		getSetting(state, data) {
			state.setting = data;
		}
	},
	actions: {
		// 设置用户信息
		async setUserInfos({
			commit
		}, data) {
			if (data) {
				commit('getUserInfos', data);
			} else {
				if (Session.get('userInfo')) commit('getUserInfos', Session.get('userInfo'));
			}
		},

		// 设置用户信息
		async setSetting({
			commit
		}, data) {
			if (data) {
				Session.set('setting', data);
				commit('getSetting', data);
			} else {
				if (Session.get('setting')) commit('getSetting', Session.get('setting'));
			}
		},
	},
};

export default userInfosModule;